package com.example.appdemo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.SimpleAdapter;


public class MainActivity extends ActionBarActivity {

	private ListView list = null;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        list = (ListView) findViewById(R.id.MyListView);
        
        List<HashMap<String, Object>> mylist = new ArrayList<HashMap<String, Object>>();
        for(int i = 0; i < 10; i++) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("ItemImage", R.drawable.ic_language_black_48dp);
            map.put("ItemText", "This is line " + i);
            mylist.add(map);
        }
        
        SimpleAdapter adapter = new SimpleAdapter(this, 
                mylist,
                R.layout.listview,
                new String[] {"ItemImage", "ItemText"},
                new int[] {R.id.ItemImage, R.id.ItemText});

        list.setAdapter(adapter);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        else if (id == R.id.action_save) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}